package com.mf.util;

import org.apache.shiro.codec.Hex;
import org.apache.shiro.crypto.RandomNumberGenerator;
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.Sha1Hash;
import org.apache.shiro.util.ByteSource;

import com.mf.entity.User;

/**
 * 用户工具类
 * 主要验证用户数据
 *
 * @author yinet
 */
public class UserUtil {
    /**
     * 判断用户密码是否正确
     * SHA1 加盐加密后进行比较
     *
     * @param User
     * @param String password
     */
    public static boolean pwdJudge(User user, String password) {
        String salt = Hex.encodeToString(StringUtil.saltBytes());    //shiro加密库
        String password1 = new Sha1Hash((password + user.getPassword_key()).getBytes(), salt, 4096).toString();

        if (user.getPassword().equals(password1)) {
            return true;
        }

        return false;
    }

    public static void main(String args[]) {

    }
}
